<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col style="display:none" :span="12">
			<p-form-item label="班组编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['workclassno', validatorRules.workclassno]"
						:trigger-change="true"
						org-fields="classsysid,classsysno,classsysname"
						dest-fields="workclassid,workclassno,workclassname"
						code="classsys_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col style="display:none" :span="12">
			<p-form-item label="班组名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workclassname', validatorRules.workclassname]" placeholder="请输入班组名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col style="display:none" :span="12">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						dest-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col style="display:none" :span="12">
			<p-form-item label="线体名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col style="display:none" :span="12">
			<p-form-item label="车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomno', validatorRules.workroomno]" placeholder="请输入车间编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col style="display:none" :span="12">
			<p-form-item label="车间名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomname', validatorRules.workroomname]" placeholder="请输入车间名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="计划数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mnum', validatorRules.mnum]" placeholder="请输入计划数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工序工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mobillno', validatorRules.mobillno]" placeholder="请输入工序工单编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="检验模板" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['spotcheckTemplate', validatorRules.spotcheckTemplate]" :trigger-change="true" dictCode="mes_spotcheck_template" placeholder="请选择检验模板"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="检验状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'istates', validatorRules.istates]" placeholder="请输入检验状态"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="检验判定" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['decide', validatorRules.decide]" :trigger-change="true" dictCode="mes_is_qualified" placeholder="请选择检验判定"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'personnel', validatorRules.personnel]" placeholder="请输入点检人员"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'theTallyTime', validatorRules.theTallyTime]" placeholder="请输入点检时间"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesMfOpenLineInspectionListModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        workclassno:{},
        workclassname:{},
        lineno:{},
        linename:{},
        workroomno:{},
        workroomname:{},
        mnum:{rules: [{ required: true, message: '请输入计划数量!' }]},
        mobillno:{rules: [{ required: true, message: '请输入工序工单编号!' }]},
        spotcheckTemplate:{rules: [{ required: true, message: '请输入检验模板!' }]},
        istates:{},
        decide:{},
        personnel:{},
        theTallyTime:{},
        },
        url: {
          add: '/mes-manufacture/auto/mesMfOpenLineInspectionList/add',
          edit: '/mes-manufacture/auto/mesMfOpenLineInspectionList/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'workclassno','workclassname','lineno','linename','workroomno','workroomname','mnum','mobillno','spotcheckTemplate','istates','decide','personnel','theTallyTime','createBy','createTime','updateBy','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'workclassno','workclassname','lineno','linename','workroomno','workroomname','mnum','mobillno','spotcheckTemplate','istates','decide','personnel','theTallyTime','createBy','createTime','updateBy','updateTime'))
      },

      
    }
  }
</script>
